{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LightGlue-ONNX Demo\n",
    "This demo shows how to export LightGlue to ONNX and perform inference with ONNXRuntime."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from export import export_onnx\n",
    "from infer import infer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ONNX Export\n",
    "In this example we use SuperPoint features combined with LightGlue."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "extractor_type = \"superpoint\"  # \"disk\"\n",
    "extractor_path = f\"weights/{extractor_type}.onnx\"\n",
    "lightglue_path = f\"weights/{extractor_type}_lightglue.onnx\"\n",
    "\n",
    "export_onnx(\n",
    "    extractor_type=extractor_type,\n",
    "    extractor_path=extractor_path,\n",
    "    lightglue_path=lightglue_path,\n",
    "    dynamic=True,  # for dynamic image size\n",
    "    max_num_keypoints=None,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ONNX Inference"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "m_kpts0, m_kpts1 = infer(\n",
    "    img_paths=[\"assets/DSC_0410.JPG\", \"assets/DSC_0411.JPG\"],\n",
    "    extractor_type=extractor_type,\n",
    "    extractor_path=extractor_path,\n",
    "    lightglue_path=lightglue_path,\n",
    "    img_size=512,\n",
    "    viz=True,\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
